//
//  NSString+URL.m
//  hainingOASystem
//
//  Created by michael on 2017/12/4.
//  Copyright © 2017年 czd. All rights reserved.
//

#import "NSString+URL.h"

@implementation NSString (URL)
-(NSString *)URLEncodedString
{
    // CharactersToBeEscaped = @":/?&=;+!@#$()~',*";
    // CharactersToLeaveUnescaped = @"[].";
    
    NSString *encodedString = (NSString *)
    CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                              (CFStringRef)self,
                                                              NULL,
                                                              (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                              kCFStringEncodingUTF8));
    
    return encodedString;
}

-(NSString *)URLDecodedString
{
    
    NSString *decodedString=(__bridge_transfer NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL, (__bridge CFStringRef)self, CFSTR(""), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
    
    return decodedString;
}
- (BOOL) isBlankString:(NSString *)string {

     if (string == nil || string == NULL) {

        return YES;

     }

     if ([string isKindOfClass:[NSNull class]]) {

         return YES;

     }

     if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {

         return YES;

     }

     return NO;

 }
@end
